﻿// ------------------------------------------------------------------
// DO NOT REMOVE THIS LINES IN ANY TIMES WILL BE.
// Original author: agehack
// Project name: Putingun
// ------------------------------------------------------------------

using System;
using WMPLib;

namespace Putingun
{
    public static class PvdRadio
    {
        public static WindowsMediaPlayer Player = null;
        public const string PlayDefaultURL = "http://anon.fm:8000/radio";
        public const string PlayDefaultLowURL = "http://anon.fm:8000/radio-low";

        private static int vol = 100;

        public static bool IsPlaying
        {
            get { return Player != null; }
        }
        public static bool IsStopped { get { return Player == null; } }
        public static int Volume
        {
            get { return vol; }
            set { vol = value; Player.settings.volume = vol; }
        }
        public static void PlayStart(string url)
        {
            if (!IsStopped)
                throw new ApplicationException("radio is not stopped yet.");
            Player = new WMPLib.WindowsMediaPlayer();
            Player.URL = url;
            Player.controls.play();
            Player.settings.volume = vol;
        }
        public static void PlayStart(bool lowq)
        {
            if (!lowq)
                PlayStart(PlayDefaultURL);
            else PlayStart(PlayDefaultLowURL);
        }
        public static void PlayStop()
        {
            if (!IsPlaying && !IsStopped)
                throw new ApplicationException("Radio is not playing or busy!");

            Player.close();
            Player = null;
        }
    }
}
